package com.ydy.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/redis")
public class RedisController {

    private final RedisTemplate<String, Object> redisTemplate;

    /**
     * ip:8080/redis/get
     * @param key
     * @return
     */
    @GetMapping("/get")
    public String get(String key) {
        return   (String) redisTemplate.opsForValue().get(key);

    }

    /**
     * ip:8080/redis/set
     * @param key
     * @param value
     */
    @GetMapping("/set")
    public void set(String key, String value) {
        redisTemplate.opsForValue().set(key, value);
        String o = (String)redisTemplate.opsForValue().get(key);
        log.info("set key:{} value:{}", key, o);
    }
}
